<!-- HTML header for doxygen 1.8.13-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Taskflow Handbook</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname"><a href="https://taskflow.github.io/">Taskflow</a>
   &#160;<span id="projectnumber">3.0.0-Master-Branch</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('classtf_1_1ObserverInterface.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#friends">Friends</a> &#124;
<a href="classtf_1_1ObserverInterface-members.html">List of all members</a>  </div>
  <div class="headertitle">
<div class="title">tf::ObserverInterface Class Reference<span class="mlabels"><span class="mlabel">abstract</span></span></div>  </div>
</div><!--header-->
<div class="contents">

<p>The interface class for creating an executor observer.  
 <a href="classtf_1_1ObserverInterface.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="observer_8hpp_source.html">observer.hpp</a>&gt;</code></p>
<div class="dynheader">
Inheritance diagram for tf::ObserverInterface:</div>
<div class="dyncontent">
<div class="center"><img src="classtf_1_1ObserverInterface__inherit__graph.png" border="0" usemap="#tf_1_1ObserverInterface_inherit__map" alt="Inheritance graph"/></div>
<map name="tf_1_1ObserverInterface_inherit__map" id="tf_1_1ObserverInterface_inherit__map">
<area shape="rect" id="node2" href="classtf_1_1ChromeObserver.html" title="observer interface based on Chrome Tracing format " alt="" coords="5,79,144,104"/>
<area shape="rect" id="node3" href="classtf_1_1TFProfObserver.html" title="observer interface based on Taskflow Profiler format " alt="" coords="167,79,299,104"/>
</map>
<center><span class="legend">[<a target="top" href="graph_legend.html">legend</a>]</span></center></div>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:adfd71c3af3ae2ea4f41eed26c1b6f604"><td class="memItemLeft" align="right" valign="top"><a id="adfd71c3af3ae2ea4f41eed26c1b6f604"></a>
virtual&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classtf_1_1ObserverInterface.html#adfd71c3af3ae2ea4f41eed26c1b6f604">~ObserverInterface</a> ()=default</td></tr>
<tr class="memdesc:adfd71c3af3ae2ea4f41eed26c1b6f604"><td class="mdescLeft">&#160;</td><td class="mdescRight">virtual destructor <br /></td></tr>
<tr class="separator:adfd71c3af3ae2ea4f41eed26c1b6f604"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a41e6e62f12bf9d9dc4fa74632f6825d9"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classtf_1_1ObserverInterface.html#a41e6e62f12bf9d9dc4fa74632f6825d9">set_up</a> (size_t num_workers)=0</td></tr>
<tr class="memdesc:a41e6e62f12bf9d9dc4fa74632f6825d9"><td class="mdescLeft">&#160;</td><td class="mdescRight">constructor-like method to call when the executor observer is fully created  <a href="#a41e6e62f12bf9d9dc4fa74632f6825d9">More...</a><br /></td></tr>
<tr class="separator:a41e6e62f12bf9d9dc4fa74632f6825d9"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:afa57654edd6d0fcf188a6064823f3048"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classtf_1_1ObserverInterface.html#afa57654edd6d0fcf188a6064823f3048">on_entry</a> (size_t worker_id, <a class="el" href="classtf_1_1TaskView.html">TaskView</a> task_view)=0</td></tr>
<tr class="memdesc:afa57654edd6d0fcf188a6064823f3048"><td class="mdescLeft">&#160;</td><td class="mdescRight">method to call before a worker thread executes a closure  <a href="#afa57654edd6d0fcf188a6064823f3048">More...</a><br /></td></tr>
<tr class="separator:afa57654edd6d0fcf188a6064823f3048"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a8fcff02bfcea581d280e4de0247760d3"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classtf_1_1ObserverInterface.html#a8fcff02bfcea581d280e4de0247760d3">on_exit</a> (size_t worker_id, <a class="el" href="classtf_1_1TaskView.html">TaskView</a> task_view)=0</td></tr>
<tr class="memdesc:a8fcff02bfcea581d280e4de0247760d3"><td class="mdescLeft">&#160;</td><td class="mdescRight">method to call after a worker thread executed a closure  <a href="#a8fcff02bfcea581d280e4de0247760d3">More...</a><br /></td></tr>
<tr class="separator:a8fcff02bfcea581d280e4de0247760d3"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="friends"></a>
Friends</h2></td></tr>
<tr class="memitem:a763b2f90bc53f92d680a635fe28e858e"><td class="memItemLeft" align="right" valign="top"><a id="a763b2f90bc53f92d680a635fe28e858e"></a>
class&#160;</td><td class="memItemRight" valign="bottom"><b>Executor</b></td></tr>
<tr class="separator:a763b2f90bc53f92d680a635fe28e858e"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>The interface class for creating an executor observer. </p>
<p>The <a class="el" href="classtf_1_1ObserverInterface.html" title="The interface class for creating an executor observer. ">tf::ObserverInterface</a> class let users define custom methods to monitor the behaviors of an executor. This is particularly useful when you want to inspect the performance of an executor and visualize when each thread participates in the execution of a task. To prevent users from direct access to the internal tasks, <a class="el" href="classtf_1_1ObserverInterface.html" title="The interface class for creating an executor observer. ">tf::ObserverInterface</a> provides an immutable wrapper <a class="el" href="classtf_1_1TaskView.html" title="class to access task information from the observer interface ">tf::TaskView</a> over these internal tasks.</p>
<p>Example usage:</p>
<div class="fragment"><div class="line"><span class="keyword">struct </span>MyObserver : <span class="keyword">public</span> <a class="code" href="classtf_1_1ObserverInterface.html">tf::ObserverInterface</a> {</div><div class="line"></div><div class="line">  MyObserver(<span class="keyword">const</span> <a class="codeRef" doxygen="/Users/twhuang/PhD/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml:http://en.cppreference.com/w/" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a>&amp; name) {</div><div class="line">    <a class="codeRef" doxygen="/Users/twhuang/PhD/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml:http://en.cppreference.com/w/" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;constructing observer &quot;</span> &lt;&lt; name &lt;&lt; <span class="charliteral">&#39;\n&#39;</span>;</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordtype">void</span> <a class="code" href="classtf_1_1ObserverInterface.html#a41e6e62f12bf9d9dc4fa74632f6825d9">set_up</a>(<span class="keywordtype">size_t</span> num_workers) <span class="keyword">override</span> <span class="keyword">final</span> {</div><div class="line">    <a class="codeRef" doxygen="/Users/twhuang/PhD/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml:http://en.cppreference.com/w/" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; <span class="stringliteral">&quot;settting up observer with &quot;</span> &lt;&lt; num_workers &lt;&lt; <span class="stringliteral">&quot; workers\n&quot;</span>;</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordtype">void</span> <a class="code" href="classtf_1_1ObserverInterface.html#afa57654edd6d0fcf188a6064823f3048">on_entry</a>(<span class="keywordtype">size_t</span> w, <a class="code" href="classtf_1_1TaskView.html">tf::TaskView</a> tv) <span class="keyword">override</span> <span class="keyword">final</span> {</div><div class="line">    <a class="codeRef" doxygen="/Users/twhuang/PhD/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml:http://en.cppreference.com/w/" href="http://en.cppreference.com/w/cpp/io/basic_ostringstream.html">std::ostringstream</a> oss;</div><div class="line">    oss &lt;&lt; <span class="stringliteral">&quot;worker &quot;</span> &lt;&lt; w &lt;&lt; <span class="stringliteral">&quot; ready to run &quot;</span> &lt;&lt; tv.name() &lt;&lt; <span class="charliteral">&#39;\n&#39;</span>;</div><div class="line">    <a class="codeRef" doxygen="/Users/twhuang/PhD/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml:http://en.cppreference.com/w/" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; oss.str();</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordtype">void</span> <a class="code" href="classtf_1_1ObserverInterface.html#a8fcff02bfcea581d280e4de0247760d3">on_exit</a>(<span class="keywordtype">size_t</span> w, <a class="code" href="classtf_1_1TaskView.html">tf::TaskView</a> tv) <span class="keyword">override</span> <span class="keyword">final</span> {</div><div class="line">    <a class="codeRef" doxygen="/Users/twhuang/PhD/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml:http://en.cppreference.com/w/" href="http://en.cppreference.com/w/cpp/io/basic_ostringstream.html">std::ostringstream</a> oss;</div><div class="line">    oss &lt;&lt; <span class="stringliteral">&quot;worker &quot;</span> &lt;&lt; w &lt;&lt; <span class="stringliteral">&quot; finished running &quot;</span> &lt;&lt; tv.name() &lt;&lt; <span class="charliteral">&#39;\n&#39;</span>;</div><div class="line">    <a class="codeRef" doxygen="/Users/twhuang/PhD/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml:http://en.cppreference.com/w/" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> &lt;&lt; oss.str();</div><div class="line">  }</div><div class="line">};</div><div class="line">  </div><div class="line"><a class="code" href="classtf_1_1Taskflow.html">tf::Taskflow</a> taskflow;</div><div class="line"><a class="code" href="classtf_1_1Executor.html">tf::Executor</a> executor;</div><div class="line"></div><div class="line"><span class="comment">// insert tasks into taskflow</span></div><div class="line"><span class="comment">// ...</span></div><div class="line">  </div><div class="line"><span class="comment">// create a custom observer</span></div><div class="line"><a class="codeRef" doxygen="/Users/twhuang/PhD/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml:http://en.cppreference.com/w/" href="http://en.cppreference.com/w/cpp/memory/shared_ptr.html">std::shared_ptr&lt;MyObserver&gt;</a> observer = executor.<a class="code" href="classtf_1_1Executor.html#a3e68a0d779cfee1554c88c2596ae9000">make_observer</a>&lt;MyObserver&gt;(<span class="stringliteral">&quot;MyObserver&quot;</span>);</div><div class="line"></div><div class="line"><span class="comment">// run the taskflow</span></div><div class="line">executor.<a class="code" href="classtf_1_1Executor.html#a81f35d5b0a20ac0646447eb80d97c0aa">run</a>(taskflow).wait();</div></div><!-- fragment --> </div><h2 class="groupheader">Member Function Documentation</h2>
<a id="afa57654edd6d0fcf188a6064823f3048"></a>
<h2 class="memtitle"><span class="permalink"><a href="#afa57654edd6d0fcf188a6064823f3048">&#9670;&nbsp;</a></span>on_entry()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">virtual void tf::ObserverInterface::on_entry </td>
          <td>(</td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>worker_id</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="classtf_1_1TaskView.html">TaskView</a>&#160;</td>
          <td class="paramname"><em>task_view</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">pure virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>method to call before a worker thread executes a closure </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">worker_id</td><td>the id of this worker thread </td></tr>
    <tr><td class="paramname">task_view</td><td>a constant wrapper object to the task </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a8fcff02bfcea581d280e4de0247760d3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a8fcff02bfcea581d280e4de0247760d3">&#9670;&nbsp;</a></span>on_exit()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">virtual void tf::ObserverInterface::on_exit </td>
          <td>(</td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>worker_id</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="classtf_1_1TaskView.html">TaskView</a>&#160;</td>
          <td class="paramname"><em>task_view</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">pure virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>method to call after a worker thread executed a closure </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">worker_id</td><td>the id of this worker thread </td></tr>
    <tr><td class="paramname">task_view</td><td>a constant wrapper object to the task </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a41e6e62f12bf9d9dc4fa74632f6825d9"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a41e6e62f12bf9d9dc4fa74632f6825d9">&#9670;&nbsp;</a></span>set_up()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">virtual void tf::ObserverInterface::set_up </td>
          <td>(</td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>num_workers</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">pure virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>constructor-like method to call when the executor observer is fully created </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">num_workers</td><td>the number of the worker threads in the executor </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="observer_8hpp_source.html">observer.hpp</a></li>
</ul>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><b>tf</b></li><li class="navelem"><a class="el" href="classtf_1_1ObserverInterface.html">ObserverInterface</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li>
  </ul>
</div>
</body>
</html>
